home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / VGA_VUL2.ZIP / FADE.ASM next >
Assembly Source File  |  1995-06-17  |  10KB  |  229 lines

  1. ;==============================================================================;
  2. ;                                                                              ;
  3. ;   Assembler program by Vulture.                                              ;
  4. ;                                                                              ;
  5. ;   This program will slowly fade-up a picture on the screen. Then it will     ;
  6. ;   wait for you to press escape before it fades the screen to black.          ;
  7. ;                                                                              ;
  8. ;   Pretty basic stuff here. But it's important to fully understand what       ;
  9. ;   is done here. When you get the idea, you can create your own cewl fx       ;
  10. ;   using the palette. Like palette rotations... Read the doc file for         ;
  11. ;   more info.                                                                 ;
  12. ;                                                                              ;
  13. ;   Greetinx,                                                                  ;
  14. ;                                                                              ;
  15. ;         Signed:   Vulture                                                    ;
  16. ;                                                                              ;
  17. ;==============================================================================;
  18.  
  19. DOSSEG        ; Sort segment like highlevel languages do
  20. .MODEL SMALL  ; Code & data both < 64 kB, seperate segments
  21. .STACK 200h   ; Define a 512 byte stack
  22. .286          ; Allow 80286 instructions in your code
  23. .DATA         ; Data segment starts here (empty)
  24. .CODE         ; Code segment starts here
  25. ASSUME cs:@code,ds:@code       ; cs and ds pointing to codesegment
  26.  
  27. ; === DATA ===
  28.  
  29. INCLUDE Picture.dat          ; Picture file with colorvalues (lineair)
  30. INCLUDE Palette.dat          ; Palette file with RGB values
  31.  
  32. Credits DB   13,10,"Code and gfx by Vulture.",13,10,"$" ; Important message :)
  33.  
  34. Parray  DB   768*2 DUP (?)   ; Array to hold 2 entire palettes
  35.  
  36. ; === PROCEDURES ===
  37.  
  38. SetVGA PROC NEAR             ; Get into VGA mode
  39.     mov     ax,0013h         ; Set the videomode 320*200*256
  40.     int     10h              ; call VID interrupt
  41.     ret                      ; Return to main program
  42. SetVGA ENDP
  43.  
  44. SetText PROC NEAR            ; Get into character mode
  45.     mov     ax,0003h         ; Set 80x25x16 char mode
  46.     int     10h              ; call VID interrupt
  47.     ret                      ; Return to main program
  48. SetText ENDP
  49.  
  50. WaitVrt PROC NEAR            ; Waits for vertical retrace to reduce "snow"
  51.     mov     dx,3dah
  52. Vrt:
  53.     in      al,dx
  54.     test    al,1000b         ; Test 3rd bit
  55.     jnz     Vrt              ; Wait until Verticle Retrace starts
  56. NoVrt:
  57.     in      al,dx
  58.     test    al,1000b         ; Test 3rd bit again
  59.     jz      NoVrt            ; Wait until Verticle Retrace ends
  60.     ret                      ; Return to main program
  61. WaitVrt ENDP
  62.  
  63. SavePalette PROC NEAR        ; Save entire palette into an array
  64.     cli                      ; Clear interrupts
  65.     lea     bp,Parray        ; bp points to offset Palette array
  66.     mov     dx,03c7h         ; Read register
  67.     xor     al,al            ; Set al to 0 (start reading at color 0)
  68.     out     dx,al            ; Give info to VGA
  69.     mov     dx,03c9h         ; Data register
  70.     mov     cx,768           ; Save all colors (256*3)
  71. Saving:
  72.     in      al,dx            ; Get what's in the register (read)
  73.     and     al,00111111b     ; Mask of the upper 2 bits (value=0..63)
  74.     mov     byte ptr [bp],al ; Save value into array
  75.     mov     al,0             ; Set value to 0
  76.     mov     byte ptr [bp+768],al  ; And save into second layer of array
  77.     inc     bp               ; Point to next cel in aray
  78.     loop    Saving           ; And loop while cx > 0
  79.     sti                      ; Enable interrupts again
  80.     ret
  81. SavePalette ENDP
  82.  
  83. BlackOut PROC NEAR           ; Reset all R,G,B values to 0
  84.     cli
  85.     mov     dx,03c8h         ; Write register
  86.     xor     al,al            ; Start at color 0 (and set R,G,B to 0 too)
  87.     out     dx,al            ; Pass info to VGA
  88.     mov     dx,03c9h         ; Data register
  89.     mov     cx,768           ; Do all colors (256*3)
  90. Reset:
  91.     out     dx,al            ; Out all zero's to VGA
  92.     loop    Reset            ; Loop while cx > 0
  93.     sti
  94.     ret
  95. BlackOut ENDP
  96.  
  97. FadeOut PROC NEAR            ; Fades the screen to black
  98.     cli                      ; Disable interrupts
  99.     lea     bp,Parray        ; Load offset Palette array
  100.     mov     cx,64            ; Set loopcounter
  101. Loop64:
  102.     xor     bx,bx            ; Set bx to 0
  103. Loop768:
  104.     cmp     byte ptr [bp],0  ; Is it 0 already?
  105.     je      FadeOn
  106.     dec     byte ptr [bp]    ; Decrease the value with 1
  107. FadeOn:
  108.     inc     bp               ; Point to next cel in array
  109.     inc     bx               ; Increase loopcounter
  110.     cmp     bx,768           ; Done all registers?
  111.     jl      Loop768          ; If not, loop again
  112.     push    cx               ; Save first loopcounter
  113.     mov     cx,768           ; Write all new R,G,B values
  114.     call    WaitVrt          ; Wait for a vertical retrace
  115.     call    WaitVrt          ; Twice
  116.     sub     bp,768           ; Reset bp to 0
  117.     mov     dx,03c8h         ; Write register
  118.     mov     al,0             ; Start writing at color 0
  119.     out     dx,al            ; Give info to VGA
  120.     mov     dx,03c9h         ; Data register
  121. WriteAll:
  122.     mov     al,byte ptr [bp] ; Get the value
  123.     out     dx,al            ; Write to VGA
  124.     inc     bp               ; Point to next cel
  125.     loop    WriteAll         ; Loop while cx > 0
  126.     sub     bp,768           ; Point to start array again
  127.     pop     cx               ; Restore loopcounter from stack
  128.     loop    Loop64           ; Have we done enough?
  129.     sti                      ; Enable interrupts
  130.     ret                      ; Return to main program
  131. FadeOut ENDP
  132.  
  133. FadeIn PROC NEAR             ; Fades screen to desired colors
  134.     cli                      ; Disable interrupts
  135.     lea     bp,Parray        ; Load offset Palette array
  136.     mov     cx,64            ; Set loopcounter
  137. Loop64X:
  138.     xor     bx,bx            ; Reset bx to 0
  139. Loop768X:
  140.     mov     dl,byte ptr [bp]        ; Store original value in dl
  141.     mov     dh,byte ptr [bp+768]    ; And fade-up value in dh
  142.     cmp     dl,dh                   ; Compare them
  143.     je      NextOne                 ; If they are equal then do the next one
  144.     inc     byte ptr [bp+768]       ; Else increase with 1 (second layer)
  145. NextOne:
  146.     inc     bp               ; Point to next arraycel
  147.     inc     bx               ; Increase counter
  148.     cmp     bx,768           ; Have we done all registers?
  149.     jl      Loop768X
  150.     push    cx               ; Save first loopcounter
  151.     mov     cx,768           ; Do all R,G,B values
  152.     call    WaitVrt          ; Wait for a vertical retrace
  153.     call    WaitVrt          ; Twice
  154.     mov     dx,03c8h         ; Write register
  155.     xor     al,al            ; Start writing at color 0
  156.     out     dx,al            ; Give info to VGA
  157.     mov     dx,03c9h         ; Data register
  158. WritemAll:
  159.     mov     al,byte ptr [bp] ; Get the value (bp points to second palette)
  160.     out     dx,al            ; Write to VGA
  161.     inc     bp               ; Point to next cel
  162.     loop    WritemAll        ; Loop while cx > 0
  163.     sub     bp,768*2         ; Point to start palette again (reached the end)
  164.     pop     cx               ; Restore loopcounter from stack
  165.     loop    Loop64X          ; Have we done enough?
  166.     sti                      ; Enable interrupts
  167.     ret                      ; Return to main program
  168. FadeIn ENDP
  169.  
  170. ; === MAIN PROGRAM ===
  171.  
  172. START:                       ; Main program starts here
  173.  
  174.     call    SetVGA           ; Get into VGA mode
  175.  
  176.     mov     ax,cs            ; Move CS into AX
  177.     mov     es,ax            ; es points to codesegment (data)
  178.     mov     ax,1012h         ; Select write palette function
  179.     mov     bx,0             ; Start at color 0
  180.     mov     cx,255           ; Write 256 colors ( 0-255 )
  181.     lea     dx,Palette       ; es:dx points to palette data
  182.     int     10h              ; Call VID interrupt & set palette
  183.  
  184.     call    SavePalette      ; Save entire palette
  185.     call    BlackOut         ; Set all R,G,B values to 0
  186.  
  187. ; === Initialize pointers ===
  188.     mov     ax,cs
  189.     mov     ds,ax            ; ds points to codesegment (data)
  190.     mov     ax,0a000h        ; Move VGA segment AX
  191.     mov     es,ax            ; es points to VGA
  192.  
  193. ; === Load the picture (not shown yet) ===
  194.     mov     cx,32320d        ; Number of bytes in cx
  195.     lea     si,Picture       ; ds:si => picture data
  196.     mov     di,320*50        ; es:di => startpos on screen
  197.     rep     movsb            ; Copy them all...
  198.  
  199.     call    FadeIn           ; Fade to original colors
  200.  
  201. Escape:
  202.     in      al,60h           ; Scan keyboard
  203.     cmp     al,1             ; Was escape hit?
  204.     jne     Escape           ; If not, loop
  205.  
  206.     call    FadeOut          ; Fade screen to black
  207.     call    SetText          ; Set textmode again
  208.  
  209. ; === Print string and quit ===
  210.     mov     ax,cs
  211.     mov     ds,ax            ; ds points to cs (data)
  212.     lea     dx,Credits       ; Get offset => ds:dx points to string
  213.     mov     ah,9             ; Select function 9 in AH
  214.     int     21h              ; Print string using ds:dx far-pointer
  215.     mov     ax,4c00h         ; Give control to DOS (MUST BE HERE!!!)
  216.     int     21h              ; Call interrupt and exit
  217.  
  218. END START                    ; End of C<><>L program...  :)
  219.  
  220.  
  221.  
  222.  
  223. ;  That's it. Hope it was understandable.
  224. ;  Use this in yar own programs but give credit where credit is due.
  225. ;  Took me a long time to figure thiz all out. Besides, a greet don't
  226. ;  cost ya nothing...... :)
  227.  
  228. ;      Vulture.
  229.